package cp2013;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author AcerXPS
 */
public class RegisterUI extends JPanel {

    private File f;
    private BufferedImage img;
    private JLabel lblUsername;
    private JTextField txtUsername;
    private JLabel lblPass;
    private JLabel lblRepeatPass;
    private JPasswordField pswPassword1;
    private JPasswordField pswPassword2;
    private JLabel lblFName;
    private JTextField txtFirstName;
    private JLabel lblLName;
    private JTextField txtLastName;
    private JLabel lblDOB;
    private JTextField txtdofBirth;
    private JLabel lblAddress;
    private JTextField txtaddress;
    private JLabel lblEMail;
    private JTextField txtEMail;
    private JButton btnSubmit;
    private JButton btnCancel;

    public void initiateRegisterUI() {
        try {
            f = new File("Register.jpg");
            img = ImageIO.read(f);
        } catch (IOException ex) {
            Logger.getLogger(RegisterUI.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            setBackground(Color.white);
            setLayout(null);
            setAlignmentY(JPanel.CENTER_ALIGNMENT);
            initiateLabels();
        }
    }//end of initiateRegisterUI

    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawRenderedImage(img, AffineTransform.getTranslateInstance(0, 0));
    }

    private void initiateLabels() {


        lblUsername = new JLabel("Username: ");
        lblUsername.setBounds(270, 100, 120, 15);
        txtUsername = new JTextField(15);
        txtUsername.setBounds(450, 100, 120, 20);

        lblPass = new JLabel("Password: ");
        lblPass.setBounds(270, 130, 120, 15);
        pswPassword1 = new JPasswordField(15);
        pswPassword1.setBounds(450, 130, 120, 20);

        lblRepeatPass = new JLabel("Repeat Password: ");
        lblRepeatPass.setBounds(270, 160, 120, 15);
        pswPassword2 = new JPasswordField(15);
        pswPassword2.setBounds(450, 160, 120, 20);

        lblFName = new JLabel("First Name: ");
        lblFName.setBounds(270, 190, 120, 15);
        txtFirstName = new JTextField(15);
        txtFirstName.setBounds(450, 190, 120, 20);

        lblLName = new JLabel("Last Name: ");
        lblLName.setBounds(270, 220, 120, 15);
        txtLastName = new JTextField(15);
        txtLastName.setBounds(450, 220, 120, 20);

        lblDOB = new JLabel("D.O.B.(YYYY/MM/DD): ");
        lblDOB.setBounds(270, 250, 120, 15);
        txtdofBirth = new JTextField(15);
        txtdofBirth.setBounds(450, 250, 120, 20);

        lblAddress = new JLabel("Address: ");
        lblAddress.setBounds(270, 280, 120, 15);
        txtaddress = new JTextField(15);
        txtaddress.setBounds(450, 280, 120, 20);

        lblEMail = new JLabel("e-Mail: ");
        lblEMail.setBounds(270, 310, 120, 15);
        txtEMail = new JTextField(15);
        txtEMail.setBounds(450, 310, 120, 20);

        btnSubmit = new JButton("Submit!");
        btnSubmit.setBounds(330, 380, 80, 20);
        btnCancel = new JButton("Cancel");
        btnCancel.setBounds(430, 380, 80, 20);

        add(lblUsername);
        add(txtUsername);
        add(lblPass);
        add(pswPassword1);
        add(lblRepeatPass);
        add(pswPassword2);
        add(lblFName);
        add(txtFirstName);
        add(lblLName);
        add(txtLastName);
        add(lblDOB);
        add(txtdofBirth);
        add(lblAddress);
        add(txtaddress);
        add(lblEMail);
        add(txtEMail);
        add(btnSubmit);
        add(btnCancel);

    }//end of initiateLabels()

    public void addRegisterUIListener(ActionListener listener) {
        btnSubmit.addActionListener(listener);
        btnCancel.addActionListener(listener);
    }

    /**
     * @return the password1
     */
    public JPasswordField getPassword1() {
        return pswPassword1;
    }

    /**
     * @param password1 the password1 to set
     */
    public void setPassword1(JPasswordField password1) {
        this.pswPassword1 = password1;
    }

    /**
     * @return the password2
     */
    public JPasswordField getPassword2() {
        return pswPassword2;
    }

    /**
     * @param password2 the password2 to set
     */
    public void setPassword2(JPasswordField password2) {
        this.pswPassword2 = password2;
    }

    /**
     * @return the username
     */
    public JTextField getUsername() {
        return txtUsername;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(JTextField username) {
        this.txtUsername = username;
    }

    /**
     * @return the firstName
     */
    public JTextField getFirstName() {
        return txtFirstName;
    }

    /**
     * @param firstName the firstName to set
     */
    public void setFirstName(JTextField firstName) {
        this.txtFirstName = firstName;
    }

    /**
     * @return the lastName
     */
    public JTextField getLastName() {
        return txtLastName;
    }

    /**
     * @param lastName the lastName to set
     */
    public void setLastName(JTextField lastName) {
        this.txtLastName = lastName;
    }

    /**
     * @return the DofBirth
     */
    public JTextField getDofBirth() {
        return txtdofBirth;
    }

    /**
     * @param DofBirth the DofBirth to set
     */
    public void setDofBirth(JTextField DofBirth) {
        this.txtdofBirth = DofBirth;
    }

    /**
     * @return the address
     */
    public JTextField getAddress() {
        return txtaddress;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(JTextField address) {
        this.txtaddress = address;
    }

    /**
     * @return the eMail
     */
    public JTextField geteMail() {
        return txtEMail;
    }

    /**
     * @param eMail the eMail to set
     */
    public void seteMail(JTextField eMail) {
        this.txtEMail = eMail;
    }

    /**
     * @return the submit
     */
    public JButton getSubmitButton() {
        return btnSubmit;
    }

    /**
     * @param submit the submit to set
     */
    public void setSubmitButton(JButton submit) {
        this.btnSubmit = submit;
    }

    /**
     * @return the cancel
     */
    public JButton getCancelButton() {
        return btnCancel;
    }

    /**
     * @param cancel the cancel to set
     */
    public void setCancelButton(JButton cancel) {
        this.btnCancel = cancel;
    }
}
